package com.woniu.spring.service.impl;

import com.woniu.spring.service.IPayService;

import java.math.BigDecimal;

/**
 * @program: JavaEE-EFD
 * @description: 支付实现类
 * @author: fengjd
 * @create: 2022-07-28 18:44
 **/
public class IPayServiceImpl implements IPayService {

    private static double total = 100000000;
    private static double totalP = 100000000; // 一个亿总积分

    /**
     * 积分支付
     *
     * @param money
     * @return
     */
    @Override
    public String payByPoint(double money) {
        /*将积分和money转换成decimal类, 相减,如果余额大于0,可以购买, 可以购买的话,就购买,并把余额设置 */
        BigDecimal totalPBigDecimal = new BigDecimal(totalP);
        BigDecimal subtract = totalPBigDecimal.subtract(new BigDecimal(money));
        if (subtract.compareTo(BigDecimal.ZERO) >= 0) {
            totalP = subtract.floatValue();
            return "success";
        } else {

            return "fail";
        }

    }

    /**
     * 人民币支付
     *
     * @param money
     * @return
     */
    @Override
    public String payRMB(double money) {
        BigDecimal totalBigDecimal = new BigDecimal(total);
        BigDecimal subtract = totalBigDecimal.subtract(new BigDecimal(money));
        if (subtract.compareTo(BigDecimal.ZERO) >= 0) {
            total = subtract.floatValue();
            return "success";
        } else {
            return "fail";
        }
    }
}
